<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\index\controller;
use app\common\controller\Fornt;


/**
 * 用户页面
 */
class Message extends Fornt{

  public function index(){
    $map['user_id'] = USER_ID;
    $list = model('message')->where($map)->order('id desc')->limit(3)->select();
    $this->assign('list', $list);

    return $this->fetch();
  }


  public function add(){
        if (IS_POST) {
          $content = input('post.content');
          $user_id = input('post.user_id');
          $model = model('message');
          $model->data([
            'content' => $content,
            'user_id'=> $user_id
          ]);

          $retrun = $model->save();
          if($retrun){
            $this->success('留言成功，我们会尽快给您解决');
          }else{
            $this->error('留言失败，请联系微信客服');
          }
        }
  }

  public function lists(){
    $map['user_id'] = USER_ID;
    $list = model('message')->where($map)->order('id desc')->paginate(10);
    $this->assign('list', $list);
    return $this->fetch();
  }

}
